/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Converters;

import DAO.TemaDao;
import bean.Tema;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

/**
 *
 * @author fernando
 */
public class TemaConverter implements Converter {
      @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
         if(value==null || value.isEmpty() ){
            return null;
        }
        return new TemaDao().consultarTema(Integer.valueOf(value));
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        Tema tema = (Tema) value;
        System.out.println("O id do tema no converter:" + tema.getId());
        if(tema == null || tema.getId() <= 0){
            return null;
        }
        return String.valueOf(tema.getId());
    }
    
}
